package org.bonorsoft.modules.control.service.impl;

import org.bonorsoft.common.util.oConvertUtils;
import org.bonorsoft.modules.control.entity.*;
import org.bonorsoft.modules.control.mapper.HouseMapper;
import org.bonorsoft.modules.control.service.IAddressService;
import org.bonorsoft.modules.control.service.IBuildingService;
import org.bonorsoft.modules.control.service.IHouseService;
import org.bonorsoft.modules.control.service.IResidentialService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 实有房屋信息
 * @Author: WilliamYe
 * @Date:   2021-03-01
 * @Version: V1.0
 */
@Service
public class HouseServiceImpl extends ServiceImpl<HouseMapper, House> implements IHouseService {
    @Autowired
    private IAddressService addressService;

    @Autowired
    private IBuildingService buildingService;

    @Autowired
    private IResidentialService residentialService;

    @Resource
    private HouseMapper houseMapper;


    /**
     * 根据地址编码获取建筑物详细
     * @param id
     * @return
     */
    @Override
    public Building getBuilding(String id) {
        Building build = new Building();
        Address address = addressService.getById(id);
        BeanUtils.copyProperties(address, build);
        String type = address.getDzlx();
        if (oConvertUtils.isNotEmpty(type)){
            if ("JZW".equals(type)){
                Building building = buildingService.getById(id);
                build.setDjdwGajgjgdm(building.getDjdwGajgjgdm())
                        .setDjdwGajgmc(building.getDjdwGajgmc())
                        .setDjrZh(building.getDjrZh())
                        .setDjrXm(building.getDjrXm())
                        .setDjsj(building.getDjsj())
                        .setSjly(building.getSjly())
                        .setSssqjwwgDzbm(building.getSssqjwwgDzbm())
                        .setSssqjcwgDzbm(building.getSssqjcwgDzbm())
                        .setZxdhzb(building.getZxdhzb())
                        .setZxdzzb(building.getZxdzzb());
            }
            if ("FW".equals(type)){
                Residential residential = residentialService.getById(id);
                build.setDjdwGajgjgdm(residential.getDjdwGajgjgdm())
                        .setDjdwGajgmc(residential.getDjdwGajgmc())
                        .setDjrZh(residential.getDjrZh())
                        .setDjrXm(residential.getDjrXm())
                        .setDjsj(residential.getDjsj())
                        .setSjly(residential.getSjly())
                        .setSssqjwwgDzbm(residential.getSssqjwwgDzbm())
                        .setSssqjcwgDzbm(residential.getSssqjcwgDzbm())
                        .setZxdhzb(residential.getZxdhzb())
                        .setZxdzzb(residential.getZxdzzb());

            }
        }
        return build;
    }

    @Override
    public List<Label> getLabel(String dzbm) {
        return houseMapper.getLable(dzbm);
    }


}
